<template>
    <div class="child">
        <h2>我是子组件2</h2>
        <h4>电脑：{{ computer }}</h4>
        <h4>接收子组件1传来的数：{{ toy }}</h4>
    </div>
</template>

<script lang="ts" setup name="Child">
import {onUnmounted, ref} from "vue";
import emitter from "@/utils/emitter";

let computer = ref('联想')
let toy = ref('')
// 接收数据，要绑定事件
emitter.on('save-toy', (val: any) => {
    toy.value = val
})

onUnmounted(()=> {
    emitter.off('save-toy')
})
</script>

<style scoped>
.child {
    float: right;
    margin-right: 15px;
    height: 300px;
    width: 40%;
    background-color: aliceblue;
}
</style>
